<?php
/**
 * 分类树controller
 * 
 */
namespace Home\Controller;
use Think\Controller;
class TypeTreeController extends Controller{
	public function index()
	{
   		//获取所有父级类目
		$temp=getListCat();
		if (count($temp)>0)
		{
			$typeBrand=M('type_brand');
			$brand=M('brand');
			foreach($temp as $key=>&$value)
			{
				if($value['level']==0){ continue;}
				$brandids=$typeBrand->cache(true)->where('typeid=%d',$key)->getField('brandid',true);
				if(!empty($brandids))
				{
					$map['brandid']=array('in',$brandids);
					$value['brands']=M('brand')->where($map)->getField('brandid,brandname');
				}

			}
		}
		//获取一级分类
		$levelone='';
		$levelsec='';
		foreach($temp as $key=>$value){
			if(!empty($value)){
				//二级分类树
				if($value['level'])
				{
					$levelsec[$value['pid']][]=$value;
				}else{
					$levelone[]=$value;
				}
			}
		}
		
		//获取二级分类
		$this->assign('levelone',$levelone);
		$this->assign('levelsec',$levelsec);
		$this->display();
	}
}